package com.feisuanyz.controller;

import com.feisuanyz.constant.ResultCodeConstant;
import com.feisuanyz.pojo.domain.MealDO;
import com.feisuanyz.pojo.dto.CreateGroup;
import com.feisuanyz.pojo.dto.DeleteGroup;
import com.feisuanyz.pojo.dto.MealDTO;
import com.feisuanyz.pojo.dto.RestResult;
import com.feisuanyz.pojo.dto.UpdateGroup;
import com.feisuanyz.pojo.query.MealQuery;
import com.feisuanyz.pojo.query.MealSelectionQuery;
import com.feisuanyz.pojo.query.QueryGroup;
import com.feisuanyz.pojo.vo.MealSelectionVO;
import com.feisuanyz.pojo.vo.PageResult;
import com.feisuanyz.service.MealService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 菜单管理
 *
 * @author Chenke Zhao
 * @date 2025-03-06 10:18:05
 */
@Tag(name = "菜单管理")
@RequestMapping("meal")
@RestController
public class MealController {

    @Autowired
    private MealService mealService;

    /**
     * 接口名称: 添加食物
     *
     * @param mealDTO 食物信息入参对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "接口名称: 添加食物")
    @ResponseBody
    public RestResult<Boolean> addMeal(@RequestBody @Validated(CreateGroup.class) MealDTO mealDTO) {
        Boolean result = mealService.addMeal(mealDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 删除食物
     *
     * @param mealDTO 食物信息入参对象
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "接口名称: 删除食物")
    @ResponseBody
    public RestResult<Boolean> deleteMeal(@RequestBody @Validated(DeleteGroup.class) MealDTO mealDTO) {
        Boolean result = mealService.deleteMeal(mealDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 修改食物
     *
     * @param mealDTO 食物信息入参对象
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "接口名称: 修改食物")
    @ResponseBody
    public RestResult<Boolean> updateMeal(@RequestBody @Validated(UpdateGroup.class) MealDTO mealDTO) {
        Boolean result = mealService.updateMeal(mealDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 查询用户食物
     *
     * @param mealQuery 查询用户食物入参对象
     * @return
     */
    @RequestMapping(value = "/userMeals", method = RequestMethod.GET)
    @Operation(summary = "接口名称: 查询用户食物")
    public RestResult<PageResult<MealDO>> getUserMeals(@Validated(QueryGroup.class) MealQuery mealQuery) {
        PageResult<MealDO> result = mealService.getUserMeals(mealQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * random
     *
     * @param mealSelectionQuery 食物选择查询入参实体类
     * @return
     */
    @RequestMapping(value = "/random", method = RequestMethod.GET)
    @Operation(summary = "random")
    public RestResult<MealDO> randomSelect(@Validated(QueryGroup.class) MealSelectionQuery mealSelectionQuery) {
        MealDO result = mealService.randomSelect(mealSelectionQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * history
     *
     * @param mealSelectionQuery 食物选择查询入参实体类
     * @return
     */
    @RequestMapping(value = "/history", method = RequestMethod.GET)
    @Operation(summary = "history")
    public RestResult<List<MealSelectionVO>> getSelectionHistory(@Validated(QueryGroup.class) MealSelectionQuery mealSelectionQuery) {
        List<MealSelectionVO> result = mealService.getSelectionHistory(mealSelectionQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
